<?php 
session_start();
$userid=null;
if (isset($_SESSION["userid"])==false || $_SESSION["userid"]==null) {
	header("Location: index.php");
	exit;
} else {
	$userid = $_SESSION["userid"];
}

			include("dbinit.php");
		date_default_timezone_set('Asia/Taipei');
		$colEmail = $userid;
		$tour_name = $_POST["tour_name"];
		$tour_startdate = date("o-m-d", strtotime($_POST["tour_startdate"]));
		$tour_enddate = date("o-m-d", strtotime($_POST["tour_enddate"]));		
		$tour_people = $_POST["tour_people"];
		$tour_description = $_POST["tour_description"];

		$query = "INSERT INTO ucMaintour (colEmail,colTourname,colTourdescription,colDatestart,colDateend, colPeopleCount) ";
		$query .= "VALUES ('$colEmail','$tour_name','$tour_description','$tour_startdate','$tour_enddate','$tour_people')";
		$result = mysql_query($query, $link);

		if ($result) {
			$indexTour = mysql_insert_id();
			$query = "INSERT INTO ucTourcourses (indexTour, colCoursename, colDatestart, colDateend, colCategory) VALUES ($indexTour,'init','$tour_startdate','$tour_enddate','in_process')";
			$result = mysql_query($query, $link);
			mysql_close($link);
			echo $indexTour;
			//header("location:myMainCourse.php?indexTour=$indexTour");
		} else {
			mysql_close($link);
			echo "null";
		}
?>